/*
 * Created by JFormDesigner on Fri Sep 17 14:40:07 CST 2021
 */

package com.minelx.woods.pc.form;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import com.intellij.uiDesigner.core.*;
import com.minelx.woods.pc.service.WoodsSession;

/**
 * @author aaa
 */
public class LoginDialog extends JDialog {
	private WoodsSession woodsSession;

	public LoginDialog(Window owner) {
		super(owner, "", ModalityType.APPLICATION_MODAL);
		initComponents();
	}

	private void okButtonActionPerformed(ActionEvent e) {
		String name = nameText.getText();
		String password = passwordText.getText();
		assert !name.isEmpty();
		assert !password.isEmpty();
		// log in
		woodsSession = new WoodsSession(name, password);
		dispose();
	}

	public WoodsSession getSession() {
		return woodsSession;
	}

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		dialogPane = new JPanel();
		contentPanel = new JPanel();
		label1 = new JLabel();
		panel1 = new JPanel();
		label2 = new JLabel();
		nameText = new JTextField();
		label3 = new JLabel();
		passwordText = new JTextField();
		buttonBar = new JPanel();
		okButton = new JButton();

		//======== this ========
		setTitle("\u767b\u9646");
		setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		var contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());

		//======== dialogPane ========
		{
			dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
			dialogPane.setLayout(new BorderLayout());

			//======== contentPanel ========
			{
				contentPanel.setLayout(new BorderLayout());

				//---- label1 ----
				label1.setText("\u767b\u9646");
				label1.setFont(new Font("Microsoft JhengHei Light", Font.PLAIN, 49));
				label1.setHorizontalAlignment(SwingConstants.CENTER);
				contentPanel.add(label1, BorderLayout.NORTH);

				//======== panel1 ========
				{
					panel1.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1));

					//---- label2 ----
					label2.setText("\u540d\u79f0: ");
					label2.setFont(new Font("Microsoft JhengHei Light", Font.PLAIN, 29));
					label2.setHorizontalAlignment(SwingConstants.CENTER);
					panel1.add(label2, new GridConstraints(0, 0, 1, 1,
						GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
						GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
						GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
						null, null, null));

					//---- nameText ----
					nameText.setFont(new Font("Microsoft JhengHei Light", Font.PLAIN, 29));
					panel1.add(nameText, new GridConstraints(0, 1, 1, 1,
						GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
						GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
						GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
						new Dimension(200, 0), null, null));

					//---- label3 ----
					label3.setText("\u5bc6\u7801: ");
					label3.setFont(new Font("Microsoft JhengHei Light", Font.PLAIN, 29));
					label3.setHorizontalAlignment(SwingConstants.CENTER);
					panel1.add(label3, new GridConstraints(1, 0, 1, 1,
						GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
						GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
						GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
						null, null, null));

					//---- passwordText ----
					passwordText.setFont(new Font("Microsoft JhengHei Light", Font.PLAIN, 29));
					panel1.add(passwordText, new GridConstraints(1, 1, 1, 1,
						GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
						GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
						GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
						new Dimension(200, 0), null, null));
				}
				contentPanel.add(panel1, BorderLayout.CENTER);
			}
			dialogPane.add(contentPanel, BorderLayout.CENTER);

			//======== buttonBar ========
			{
				buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
				buttonBar.setLayout(new GridBagLayout());
				((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 80};
				((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0};

				//---- okButton ----
				okButton.setText("OK");
				okButton.addActionListener(e -> okButtonActionPerformed(e));
				buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
					GridBagConstraints.CENTER, GridBagConstraints.BOTH,
					new Insets(0, 0, 0, 0), 0, 0));
			}
			dialogPane.add(buttonBar, BorderLayout.SOUTH);
		}
		contentPane.add(dialogPane, BorderLayout.CENTER);
		setSize(410, 385);
		setLocationRelativeTo(getOwner());
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	private JPanel dialogPane;
	private JPanel contentPanel;
	private JLabel label1;
	private JPanel panel1;
	private JLabel label2;
	private JTextField nameText;
	private JLabel label3;
	private JTextField passwordText;
	private JPanel buttonBar;
	private JButton okButton;
	// JFormDesigner - End of variables declaration  //GEN-END:variables
}
